<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <title>办公管理系统-修改文章</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate"/>
    <meta name="Keywords" content="keyword1,keyword2,keyword3"/>
    <meta name="Description" content="网页信息的描述"/>
    <meta name="Copyright" content="All Rights Reserved."/>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/easyUI/easyui.css">
    <!-- Sweet Alert -->
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/css/plugins/sweetalert/sweetalert.css">
</head>
<body style="padding: 10px;">

<div>
    <label style="padding: 8px 0;font-weight: bold;">标题</label><br>
    <input id="title" type="text" maxlength="500" style="width: 400px;" name="title" value="${article.title}">
</div>
<div>
    <form>
        <label style="padding: 8px 0;font-weight: bold;">内容</label>
        <textarea id="mytmce" style="width: 90%">${article.content}</textarea>
    </form>
</div>
<div>
    <label style="padding: 8px 0;font-weight: bold;">简介</label><br>
    <textarea name="briefing" id="briefing" style="width: 90%" rows="5">${article.briefing}</textarea>
</div>

<div>
    <label style="padding: 8px 0;font-weight: bold;">标签</label><br>
    <input id="label" type="text" maxlength="200" style="width: 400px;" name="label" value="${article.title}">
</div>

<div style="padding: 8px 0;font-weight: bold;">
    <span style="vertical-align: middle">是否显示</span> <input style="vertical-align: middle;margin-top: 0;" type="checkbox" id="isDisplay" name="isDisplay">&nbsp;&nbsp;&nbsp;
    <span style="vertical-align: middle">是否允许评论</span> <input style="vertical-align: middle;margin-top: 0;" type="checkbox" id="isComment" name="isComment">
    <span style="vertical-align: middle;margin-left: 10px;">文章分类</span>
    <c:forEach var="classify" items="${classifies}" varStatus="star">
        <label><input name="type_id" <c:if test="${classify.sysid == article.classifyId}">checked</c:if> style="vertical-align: middle;margin-top: 0;" type="radio" value="${classify.sysid}">${classify.classifyName}</label>
    </c:forEach>
</div>
<div style="padding-top: 20px">
    <button type="button" class="btn btn-primary" onclick="updateArticle('${article.sysid}')">保存文章</button>
</div>


<script type="text/javascript" src="${pageContext.request.contextPath}/resources/jquery/jquery.min.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/resources/jquery/jquery-migrate-1.2.1.min.js"></script>
<%--修正上传问题用的插件--%>
<script src="${pageContext.request.contextPath}/resources/jquery/jquery.form.js"></script>
<!-- 导入bootStrap的库 -->
<script type="text/javascript"
        src="${pageContext.request.contextPath}/resources/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/easyUI/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/easyUI/easyui-lang-zh_CN.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/resources/tinymce/js/tinymce/tinymce.min.js"></script>
<!--弹窗-->
<script type="text/javascript"
        src="${pageContext.request.contextPath}/resources/plugins/sweetalert/sweetalert.min.js"></script>


<script type="text/javascript">

    $(document).ready(function () {
        tinymce.init({
            selector: '#mytmce',
            upload_image_url: '${pageContext.request.contextPath}/article/image/fileUpload.jspx', //配置的上传图片的路由
            height: 400,
            menubar: false,
            plugins: ['preview', 'link', 'codesample', 'uploadimage'],
            toolbar: 'insert | undo redo  link codesample |  formatselect | bold italic backcolor  | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | uploadimage | preview',
            content_css: []

        });
    });


    function updateArticle(id) {
        var title = $("#title").val();
       if ($.trim(title)==""){
            swal("标题不能为空！","","error");
            return false;
        }
        var content = tinymce.activeEditor.getContent();
       if ($.trim(content) == "") {
            swal("内容不能为空!", "", "error");
            return false;
        }
        var briefing = $("#briefing").val();
       if ($.trim(briefing)==""){
            swal("简介不能为空!","","error");
            return false;
        }
        var classifyId = $("input[name='type_id']:checked").val();
       
        var isDisplay ;
        if ($('input[name="isDisplay"]').get(0).checked == true){
            isDisplay="Y";
        }else{
            isDisplay="N";
        }
        var isComment;
        if ($('input[name="isComment"]').get(0).checked == true){
            isComment="Y";
        }else{
            isComment="N";
        }
       $.ajax({
            url: '${pageContext.request.contextPath}/article/saveOrUpdateArticle.jspx',
            data: {'id':id,'title':title,'content': content,'briefing':briefing,'isDisplay':isDisplay,'isComment':isComment,"classifyId":classifyId},
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    swal(data.message, '保存成功', "success");
                    setTimeout(function () {
                        location.href="selectArticle.jspx";
                    }, 1500);
                } else {
                    swal("sorry", "保存失败!", "error");
                }
            },
            error: function (data) {
                swal("sorry", "服务器异常", "error");
            }
        });
    }

</script>

</body>
</html>